package router

import (
	"gino/app/controller"
	"gino/app/middleware"
	"gino/router/api"
	"github.com/gin-gonic/gin"
)

// Server ...
type Server struct {
	GinEngine *gin.Engine
}

// InitRouter ...
func InitRouter() *Server {

	server := new(Server)
	gin.SetMode(gin.DebugMode)
	server.GinEngine = gin.Default()

	server.GinEngine.Use(middleware.ZapLogger(), middleware.ZapRecovery(true))

	// 注册基础路由
	registerBaseAPI(server)

	// VI分组
	apiGroupV1 := server.GinEngine.Group("/api/v1")
	api.RegisterAPIV1(apiGroupV1)

	return server
}

// registerBaseAPI ...
func registerBaseAPI(server *Server) {
	server.GinEngine.GET("/", controller.Health)
	server.GinEngine.GET("/version", controller.Version)
}
